<template>
    <div class="text-dropdown">
        <div class="pull-down">
            <p
                type="text"
                @focus="showOptions"
                @blur="hideOptions"
                @keyup.enter="selectOption"
                @click="onclicke"
            >
                {{ selectedValue || '秀洲区' }}
            </p>
            <img src="./image/downarrow.png" />
        </div>
        <ul v-show="showDropdownOptions" class="dropdown-options">
            <li v-for="(option, index) in options" :key="index" @click="selectOption(option)">
                {{ option }}
            </li>
        </ul>
    </div>
</template>

<script>
export default {
    props: {
        options: {
            type: Array,
            required: true
        }
    },
    data() {
        return {
            selectedValue: '',
            showDropdownOptions: false
        }
    },
    methods: {
        onclicke() {
            this.showDropdownOptions = !this.showDropdownOptions
        },
        showOptions() {
            this.showDropdownOptions = true
        },
        hideOptions() {
            this.showDropdownOptions = false
        },
        selectOption(option) {
            this.selectedValue = option
            this.showDropdownOptions = false
        }
    }
}
</script>

<style>
.text-dropdown {
    position: relative;
}
ul.dropdown-options {
    position: absolute;
    margin-left: 20px;
    list-style: none;
    padding: 0;
}
.pull-down {
    display: flex;
    align-items: center;
    font-size: 20px;
    margin-top: 5px;
    font-weight: bold;
}
.pull-down p {
    display: block;
    padding: 10px;
}
</style>
